#pragma once

#include "templatetable.h"

class DOM
{
protected:
	TemplateNameTable<char*> m_values;
	TemplateNameTable<DOM*> m_subDom;
	static char * s_emptyString;
public:
	static const int 
		ERROR_NONE = 0,
		ERROR_FILE_OPEN = 1;
	void add(char * name, char * value)
	{
		m_values.add(name, value);
	}
	DOM(){}
	int load(const char * a_filename);
	DOM(const char * a_filename);
	char * getString(char * varName);
	float getFloat(char * varName);
	int getInteger(char * varName);
	bool isValueEqualTo(char * varname, char * value);
	void release()
	{
		for(int i = 0; i < m_values.size(); ++i)
		{
			delete [] m_values.getKey(i);
			char * s = m_values.get(i);
			if(s != s_emptyString)
				delete [] s;
		}
		m_values.release();
	}
	int getVarCount()
	{
		return m_values.size();
	}
	char * getVar(const int & a_index){return m_values.get(a_index);}
	char * getName(const int & a_index){return m_values.getKey(a_index);}
	int getSubCount()
	{
		return m_subDom.size();
	}
	DOM * getSub(const int & a_index)
	{
		return m_subDom.get(a_index);
	}
	char * getSubName(const int & a_index)
	{
		return m_subDom.getKey(a_index);
	}
	DOM * getSub(char * varName)
	{
		DOM ** d = m_subDom.getByKey(varName);
		if(!d)return 0;
		return *d;
	}
	~DOM(){release();}
};
